package swt.dao;

import java.sql.ResultSet;
import java.sql.SQLException;



import swt.util.RowMapper;

import swt.entity.Company;
import swt.util.DBHelp;

public class CompDao {
	private DBHelp<Company> db=new DBHelp<Company>();
	
	public Company findByComName(String compName){
		String sql="select id ,compname from t_comp where compname=?";
		return db.executeQueryForObject(sql, new CompRowMapper(), compName);
	}
	public Company findByComId(String compId){
		String sql="select id ,compname from t_comp where id=?";
		return db.executeQueryForObject(sql, new CompRowMapper(), compId);
	}
	public void save(String compName,String id){
		String sql="insert into t_comp(compname,id) values(?,?)";
		db.executeSQL(sql, compName,id);
	}private class CompRowMapper implements RowMapper<Company>{

		public Company mapperRow(ResultSet rs) throws SQLException {
			
			Company comp = new Company();
			comp.setId(rs.getString("id"));
			comp.setCompname(rs.getString("compname"));
			
			return comp;
		}
		
	}
}
